from flask import Blueprint,render_template
from ..service.junit_service import JunitService as service

junit_app = Blueprint('junitapp', __name__,template_folder='templates')

@junit_app.route('/junits')
def junits():
    return 'Hello, World!'

@junit_app.route('/junits/<int:junit_id>')
def junit(junit_id):
    profile = service.profile(junit_id)
    packages = service.packages_profile(junit_id)
    classes = service.classes_profile(junit_id)
    base = {
        'junit_id': junit_id,
    }
    return render_template('junit.html',base = base,profile = profile,packages = packages, classes = classes)

@junit_app.route('/junits/<int:junit_id>/packages/<string:package_name>')
def junit_package(junit_id,package_name):
    package_profile = service.package_profile(junit_id,package_name = package_name)
    classes = service.classes_profile(junit_id,package_name = package_name)
    base = {
        'junit_id': junit_id,
        'package_name': package_name,
    }
    return render_template('junit_package.html',base = base,profile = package_profile,classes = classes)

@junit_app.route('/junits/<int:junit_id>/packages/<string:package_name>/classes/<string:class_name>')
def junit_class(junit_id,package_name,class_name):
    base = {
        'base': {
            'junit_id': junit_id,
            'package_name': package_name,
            'class_name': class_name,
        },
        'profile': service.class_profile(junit_id,package_name,class_name),
        'tests': service.tests_profile(junit_id,package_name,class_name),
    }
    return render_template('junit_class.html',**base)